//
//  MePublishBtn.m
//  MeLive
//
//  Created by liulei on 2017/5/10.
//  Copyright © 2017年 liulei. All rights reserved.
//

#import "MePublishBtnView.h"


@interface MePublishBtnView ()<UIActionSheetDelegate>

/** 覆盖住realybtn 的一个透明按钮 */
@property (nonatomic, strong) UIButton *coverBtn;
/** 实际要现实的btn */
@property (nonatomic, strong) UIButton *realyBtn;


@end

@implementation MePublishBtnView

#pragma mark - life cycle
- (instancetype)init
{
    if (self = [super init]) {
        [self addSubview:self.realyBtn];
        [self addSubview:self.coverBtn];
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.coverBtn.frame = self.bounds;
    [self.realyBtn sizeToFit];
    CGFloat realyBtnX = self.center.x - self.width;
    CGFloat realyBtnY = self.center.y;
    self.realyBtn.center = CGPointMake(realyBtnX, realyBtnY);
}
#pragma mark - delegate
#pragma mark - event response
//- (void)coverBtnWithTouchDown
//{
//    [self.realyBtn setImage:[UIImage imageNamed:@"toolbar_live"] forState:UIControlStateNormal];
//}
- (void)coverBtnWithTouchUpInside
{
//    [self changeBtnToNormal];
    if ([self.delegate respondsToSelector:@selector(didClickPublishBtnInMePublishBtnView:)]) {
        [self.delegate didClickPublishBtnInMePublishBtnView:self];
    }
    
}
//- (void)coverBtnWithTouchDragExit
//{
//    [self changeBtnToNormal];
//}
#pragma mark - private methods
- (void)changeBtnToNormal
{
    [_realyBtn setImage:[UIImage imageNamed:@"toolbar_live"] forState:UIControlStateNormal];
}
#pragma mark - getters and setters
- (UIButton *)coverBtn
{
    if (_coverBtn == nil) {
        _coverBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//        [_coverBtn addTarget:self action:@selector(coverBtnWithTouchDown) forControlEvents:UIControlEventTouchDown];
        [_coverBtn addTarget:self action:@selector(coverBtnWithTouchUpInside) forControlEvents:UIControlEventTouchUpInside];
//        [_coverBtn addTarget:self action:@selector(coverBtnWithTouchDragExit) forControlEvents:UIControlEventTouchDragExit];
    }
    return _coverBtn;
}
- (UIButton *)realyBtn
{
    if (_realyBtn == nil) {
        _realyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self changeBtnToNormal];
    }
    return _realyBtn;
}


@end
